import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

public class testHttp {
@Test
public void testGet() {
	String result = HttpUtil.get("https://www.baidu.com");
	System.out.println(result);
}

@Test
public void testGetByParam() {
	// 构建查询参数
	Map<String, Object> paramMap = new HashMap<>();
	paramMap.put("pageNum", 1);
	paramMap.put("pageSize", 5);
	// 分页查询护理项目
	HttpResponse authorization = HttpUtil.createRequest(Method.GET, "http://localhost/dev-api/serve/project/list")
										 .header("Authorization", "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImMyMWFjMGYyLTdkN2ItNGRhYy05ZTA4LTZjYzA5ZTEyZmQzYSJ9.4MU5ZQUm4xKmXewyeoBsEJsTSAtC7PPZDsbywKTQ-TV2g5iMNnlinabqR5056PxLPTOSVk_yteIIHk_WcXdS7w")
										 .form(paramMap)
										 .execute();
	String body = authorization.body();
	System.out.println(body);
}

@Test
public void testPost() {
	Map<String, Object> map = new HashMap<>();
	map.put("name", "测试02");
	map.put("status", 0);
	HttpResponse response = HttpUtil.createRequest(Method.POST, "http://localhost/dev-api/serve/project")
									.header("Authorization", "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImMyMWFjMGYyLTdkN2ItNGRhYy05ZTA4LTZjYzA5ZTEyZmQzYSJ9.4MU5ZQUm4xKmXewyeoBsEJsTSAtC7PPZDsbywKTQ-TV2g5iMNnlinabqR5056PxLPTOSVk_yteIIHk_WcXdS7w")
									.body(JSONUtil.toJsonStr(map))
									.execute();
	String body = response.body();
	System.out.println(body);
}

//天气
@Test
public void testWeather() {
	String host = "https://ali-weather.showapi.com";
	String path = "/day15";
	String appcode = "4731ab0869c541fb9b57da52c5a57a2c";
	Map<String, Object> querys = new HashMap<>();
	querys.put("area", "丽江");
	HttpResponse response = HttpUtil.createRequest(Method.GET, host + path)
										 .header("Authorization", "APPCODE " + appcode)
										 .form(querys)
										 .execute();
	System.out.println(response.body());
}

//快递查询
@Test
public void testExpress() {
	String host = "https://kzexpress.market.alicloudapi.com";
	String path = "/api-mall/api/express/query";
	String appcode = "4731ab0869c541fb9b57da52c5a57a2c";
	Map<String, Object> bodys = new HashMap<>();
	bodys.put("expressNo", "434468417216159");
	bodys.put("mobile", "18273392651");
	HttpResponse response = HttpUtil.createRequest(Method.POST, host + path)
										 .header("Authorization", "APPCODE " + appcode)
										 .form(bodys)
										 .execute();
	System.out.println(response.body());
}

//微信登录
@Test
public void testWxLogin() {
	Map<String, Object> stringObjectMap = new HashMap<>();
	stringObjectMap.put("appid", "wx300adaf511dc1c08");
	stringObjectMap.put("secret", "2d14d2f6e7c83bbbf4fc07fdf4756b1e");
	stringObjectMap.put("js_code", "0f3REc0w3uBpS43N161w3ChwYE0REc0C");
	stringObjectMap.put("grant_type", "authorization_code");
	String response = HttpUtil.get("https://api.weixin.qq.com/sns/jscode2session ", stringObjectMap);
	System.out.println(response);
}
}


